package com.wish.g3.account.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wish.common.core.utils.poi.ExcelUtil;
import com.wish.common.core.web.controller.BaseController;
import com.wish.common.core.web.domain.AjaxResult;
import com.wish.common.core.web.page.TableDataInfo;
import com.wish.common.log.annotation.Log;
import com.wish.common.log.enums.BusinessType;
import com.wish.common.security.annotation.RequiresPermissions;
import com.wish.g3.account.entity.CwHailianDealPerDay;
import com.wish.g3.account.service.ICwHailianDealPerDayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 海链财务报表(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入) 前端控制器
 * </p>
 *
 * @author wish
 * @since 2022-11-23
 */
@RestController
@RequestMapping("/day")
public class CwHailianDealPerDayController extends BaseController {

    @Autowired
    private ICwHailianDealPerDayService tbCwHailianDealPerDayService;

    /**
     * 查询海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)列表
     */
    @RequiresPermissions("account:day:list")
    @GetMapping("/list")
    public TableDataInfo list(CwHailianDealPerDay tbCwHailianDealPerDay)
    {
        startPage();

        QueryWrapper wapper = new QueryWrapper();

        if (tbCwHailianDealPerDay.getOperationType() != null){
            wapper.eq("operation_type",tbCwHailianDealPerDay.getOperationType());
        }
        if (tbCwHailianDealPerDay.getDealDate() != null){
            wapper.eq("deal_date",tbCwHailianDealPerDay.getDealDate());
        }

        List<CwHailianDealPerDay> list = tbCwHailianDealPerDayService.list(wapper);

        return getDataTable(list);
    }

    /**
     * 导出海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)列表
     */
    @RequiresPermissions("account:day:export")
    @Log(title = "海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CwHailianDealPerDay tbCwHailianDealPerDay)
    {
        List<CwHailianDealPerDay> list = tbCwHailianDealPerDayService.list();
        ExcelUtil<CwHailianDealPerDay> util = new ExcelUtil<CwHailianDealPerDay>(CwHailianDealPerDay.class);
        util.exportExcel(response, list, "海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)数据");
    }

    /**
     * 获取海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)详细信息
     */
    @RequiresPermissions("account:day:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCwHailianDealPerDayService.getById(id));
    }

    /**
     * 新增海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)
     */
    @RequiresPermissions("account:day:add")
    @Log(title = "海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CwHailianDealPerDay tbCwHailianDealPerDay)
    {
        return toAjax(tbCwHailianDealPerDayService.save(tbCwHailianDealPerDay));
    }

    /**
     * 修改海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)
     */
    @RequiresPermissions("account:day:edit")
    @Log(title = "海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CwHailianDealPerDay tbCwHailianDealPerDay)
    {
        return toAjax(tbCwHailianDealPerDayService.saveOrUpdate(tbCwHailianDealPerDay));
    }

    /**
     * 删除海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)
     */
    @RequiresPermissions("account:day:remove")
    @Log(title = "海链财务报(批处理对线上收入每天分类汇总统计一条记录，目前只有线上收入)", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCwHailianDealPerDayService.removeByIds(Arrays.asList(ids)));
    }

}
